import {encrypt} from '@/util/sm-crypto/sm3'
import SM4 from '@/util/sm-crypto/sm4'

/**
 * 国密SM3加密
 * @param value
 * @returns {*}
 */
export function sm3Encrypt (value) {
  if (value === "")
    return "";
  let encryptValue = encrypt(value);
  return encryptValue;
}

/**
 * 国密SM4加密
 * @param value
 * @returns {*}
 */
export function sm4Encrypt (value, keyStr = 'com.inspur.dgov@') {
  if (value === "")
    return "";
  let sm4Config = {
    key: keyStr,
    mode: 'cbc',
    iv: keyStr,
    padding: 'pkcs5',
  }
  let sm4 = new SM4(sm4Config)
  let encryptValue = sm4.encrypt(value);
  return encryptValue;
}

/**
 * 国密SM4解密
 * @param value
 * @returns {*}
 */
export function sm4Decrypt (value, keyStr = 'com.inspur.dgov@') {
  if (value === "")
    return "";
  let sm4Config = {
    key: keyStr,
    mode: 'cbc',
    iv: keyStr,
    padding: 'pkcs5',
  }
  let sm4 = new SM4(sm4Config)
  let decryptValue = sm4.decrypt(value);
  return decryptValue;
}
